import SwiftUI

struct RootView: View {
    @AppStorage("userName") private var userName: String = ""
    @State private var showNameSheet: Bool = false
    @StateObject private var sensor = SensorRecorder()
    
    var body: some View {
        TabView {
            ScenarioListView()
                .environmentObject(sensor)
                .tabItem {
                    Label("采集", systemImage: "record.circle")
                }
            
            // ContentView 已被注释，避免与 SensorRecorder 产生资源冲突
            // ContentView 创建了独立的 CMHeadphoneMotionManager
            // 如需实时数据展示，请在 ScenarioListView 中查看
            /*
            ContentView()
                .tabItem {
                    Label("实时数据", systemImage: "waveform.path.ecg")
                }
            */
        }
        .tint(.blue)
        .onAppear { if userName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { showNameSheet = true } }
        .sheet(isPresented: $showNameSheet) {
            NameOnboardingSheet { showNameSheet = false }
                .presentationDetents([.height(300), .medium])
                .presentationCornerRadius(20)
        }
    }
}

#Preview {
    RootView()
}
